#@layout()

#define content()
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north',border:true">
        #include("/common/sa_menus.html")
    </div>
    <div data-options="region:'center',border:true">
        <div id="datagridId"></div>

        <div id="datagridTb">
            <div class="row">
                <div class="row">
                    <div class="col-md-12" style="padding: 5px 25px;">
                        <a href="javascript:;" class="easyui-linkbutton"
                           data-options="iconCls:'icon-pill_add',plain:true" id='resource_add'>增加资源</a>
                        <a href="javascript:;" class="easyui-linkbutton"
                           data-options="iconCls:'icon-pill_go',plain:true" id='resource_edit'>编辑资源</a>
                        <a href="javascript:;" class="easyui-linkbutton"
                           data-options="iconCls:'icon-pill_delete',plain:true" id='resource_remove'>移除资源</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

#end


#define css()

#end


#define js()


<script type="text/javascript">
    var _datagrid = "datagridId", _form = "formId", _datagridTb = "datagridTb";
    var datagridListUrl = contextRootPath + '/resource/findAll';

    $(function () {
        //初始化表格
        $("#" + _datagrid).treegrid({
            url: datagridListUrl,
            title: '资源管理',
            fit: true,
            toolbar: '#' + _datagridTb,
            rownumbers: true,
            animate: true,
            collapsible: true,
            fitColumns: true,
            method: 'get',
            idField: 'resourceId',
            treeField: 'resourceName',
            columns: [[
                {title: '资源名称', field: 'resourceName', width: 180},
                {title: '地址', field: 'url', width: 100},
                {
                    field: 'resourceType', title: '类型', width: 200, formatter: function (value, row, index) {
                        if (value === 1) {
                            return '系统菜单';
                        } else {
                            return '系统功能';
                        }
                    }
                }, {
                    field: 'isEnable',
                    title: "是否启用",
                    sortable: true,
                    formatter: function (value, row, index) {
                        if (value !== '1') {
                            return "不启用";
                        } else {
                            return "启用";
                        }
                    }
                },
                {title: '备注 ', field: 'des', width: 80}
            ]]
        });


        $("#resource_add").on('click', function () {

            var params = {};
            params.title = "增加资源";
            params.width = 2000;
            params.height = 2000;
            params.top = '10px';
            params.modal = true;
            params.iconCls = 'icon-application_add';
            params.url = contextRootPath + '/resource/add';
            params.buttons = [{
                text: '提交',
                iconCls: 'icon-application_go',
                handler: function () {
                    datagrid_save('add');
                }
            }, {
                text: '重置',
                iconCls: 'icon-application_side_contract',
                handler: function () {
                    clearForm('formId')
                }
            }];

            crud_dlg(params);
        });


        $("#resource_edit").on('click', function () {
            var selected = $('#' + _datagrid).datagrid('getSelected');


            if (selected == null) {
                $.messager.alert("提示框", "请选择需要操作的资源!", "warning");
                return;
            }

            var selections = $('#' + _datagrid).datagrid('getSelections');

            if (selections.length < 1) {
                $.messager.alert("提示框", "请选择需要操作的资源!", "warning");
                return;
            } else if (selections.length > 1) {
                $.messager.alert("提示框", "编辑的资源为多个，请重新选择!", "warning");
                return;
            }

            var params = {};
            params.title = "编辑资源";
            params.width = 2000;
            params.height = 2000;
            params.top = '10px';
            params.modal = true;
            params.iconCls = 'icon-application_edit';
            params.url = contextRootPath + '/resource/edit/' + selected["resourceId"];
            params.buttons = [{
                text: '提交',
                iconCls: 'icon-application_go',
                handler: function () {
                    datagrid_save();
                }
            }, {
                text: '关闭',
                iconCls: 'icon-application_side_contract',
                handler: function () {
                    $('#crud_dlg').dialog('close');
                }
            }];

            crud_dlg(params);
        });


        $("#resource_remove").on('click', function () {
            var selected = $('#' + _datagrid).datagrid('getSelected');


            if (selected == null) {
                $.messager.alert("提示框", "请选择需要操作的资源!", "warning");
                return;
            }

            $.messager.confirm('确认框', '请确定需要删除所选择的资源么？', function (r) {
                if (r) {
                    $.post(contextRootPath + "/resource/remove?resourceId=" + selected["resourceId"], function (data) {
                        var params = {};
                        params.element = _datagrid;
                        params.data = data;
                        params.isClose = false;
                        resultCallback(params);
                        $('#' + _datagrid).treegrid("reload");
                    }, 'json');
                }
            });


        });

    });


    function getDictByDictType(dtId) {
        $("#" + _datagrid).datagrid({
            queryParams: {
                "dict.dt_id": dtId
            }
        });
    }
</script>

#end



